<?php

class category {

  function category () {
  }

  function prepareCats (&$shop,$params = '') {
     global $SCRIPT_NAME;
     if (!$this->catobj){
      $this->catobj          = $shop->call('dbaLtdCategory','getVisibleCategoriesObj',$shop->cfgSF['lang']);
      $shop->regMod("catobj",$this->catobj);
      $this->table           = $this->catobj->getTable();
      $this->cat = $shop->getSessionVar('holdCat');
      $this->childtable      = $this->catobj->getCategoriesByParent($this->cat);
      $this->childtablecount = 0;
     }
  }

  function setChildTable(&$shop,$params = ''){
    if (!is_array($params))
      $cat = $this->cat;
    else
      $cat = $params[0];
    if ($this->catobj->isParent($cat)){
     $this->childtable      = $this->catobj->getCategoriesByParent($cat);
     return true;
    }
  }

  function hiermenu (&$shop,$params = '') {
     $shop->ml->load('hiermenu',array('id' => 'id', 'templates' => $shop->cfgTpl, 'frames' => $shop->cfgTplFrame, 'parent_id' => 'top', 'table' => $this->table, 'descr' => 'name','script_name' => $shop->getVar('SCRIPT_NAME'), 'always_change_dc' => $params[0]));
     $shop->out($shop->mod["hiermenu"]->get_menuStr());
  }

  function nextCat (&$shop,$params = '') {
     if ($this->childtable[$this->childtablecount]){
        while (list($name,$value) = each($this->childtable[$this->childtablecount])){
	  if (!preg_match('/^\d+$/',$name)){
           if ($name == 'display_url') $name = 'tpl';
	   $shop->setBlockVar($name,$value);
	  }
	}
        $this->childtablecount++;
	return true;
     }
  }



  function currentCat (&$shop,$params = '') {
     $currentCat = $this->catobj->getCategoryByID($this->cat);
     if ($currentCat){
        while (list($name,$value) = each($currentCat)){
	  if (!preg_match('/^\d+$/',$name)){
	   $shop->setBlockVar($name,$value);
	  }
	}
	return true;
     }
  }

  function catPath (&$shop,$params = ''){
    if ($this->catobj)
      $shop->out($this->catobj->extractPathStr($shop->getSessionVar('displayCat'),'name',$params[0],true));
    else
      print "<b>Error:</b> call prepareCats() first<br>";
  }

  function categoryLink (&$shop,$params){
    $shop->out('<a href="'.$shop->getVar('SCRIPT_NAME').'?a=cc&dc='.$shop->getVar('id').'&t='.$shop->getVar('tpl').'&tr='.$shop->getVar('TEMPLATE_ROOT').'" target="'.$shop->cfgTplFrame['artlist'].'">'.$params[0].'</a>');
  }

  function categoryBackLink (&$shop,$params){
    $parent = $this->catobj->getParent($shop->getVar('DISPLAY_CAT'));
    if ($parent){
      $shop->out('<a href="'.$shop->getVar('SCRIPT_NAME').'?a=cc&dc='.$parent['id'].'&t='.$parent['display_url'].'&tr='.$shop->getVar('TEMPLATE_ROOT').'" target="'.$shop->cfgTplFrame['artlist'].'">'.$params[0].'</a>');
      return true;
    }
  }

  function categoryUrl (&$shop,$params=''){
    $shop->out($shop->getVar('SCRIPT_NAME').'?a=cc&dc='.$shop->getSessionVar('displayCat').'&t='.$shop->getVar('CAT_TPL').'&tr='.$shop->getVar('TEMPLATE_ROOT'));
  }

}

?>
